/**
 * Created by dev-001 on 2017/2/27.
 * 答案
 */
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;

const AnswerSchema = new Schema({
    name: String,
    type: Number,//类型
    school: {
        type: ObjectId,
        ref: 'School'
    },
    grade: {
        type: ObjectId,
        ref: 'Grade'
    },
    clazz: {
        type: ObjectId,
        ref: 'Clazz'
    },
    exam: {
        type: ObjectId,
        ref: 'Exam'
    },
    group: {
        type: ObjectId,
        ref: 'QuestionGroup'
    },
    question: {
        type: ObjectId,
        ref: 'Question'
    },
    points: [{
        type: ObjectId,
        ref: 'Point'
    }],
    ability: [{
        type: ObjectId,
        ref: 'Ability'
    }],
    status: Boolean, //是否已阅完毕
    score: Number, //最终得分
    user: {
        type: ObjectId,
        ref: 'User'
    },
    tempId: String,//由于切图和打分是异步的，所以必须有个临时标识来表明切除来这一组图是哪个同学的（因为此时还没开始识别呢，分开的好多就不多说了）
    content: [String],//用户答案
    attachment: {
        type: ObjectId,
        ref: 'Attachment'
    },//用户答案图片
    createdAt: Date,
    updatedAt: Date
});

AnswerSchema.pre('save', function (next) {
    this.createdAt = new Date();
    next();
});

export default mongoose.model('Answer', AnswerSchema);